home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / var / lib / dpkg / info / ufw.postinst < prev    next >
Text File  |  2009-09-23  |  4KB  |  144 lines

  1. #!/bin/sh -e
  2.  
  3. . /usr/share/debconf/confmodule
  4.  
  5. RULES_PATH="/etc/ufw"
  6. USER_PATH="/lib/ufw"
  7. TEMPLATE_PATH="/usr/share/ufw"
  8.  
  9. enable_ufw() {
  10.     ans=""
  11.     if [ "$1" = "true" ]; then
  12.         ans="yes"
  13.     elif [ "$1" = "false" ]; then
  14.         ans="no"
  15.     else
  16.         return 1
  17.     fi
  18.  
  19.     sed -i "s/^ENABLED=.*/ENABLED=$ans/" /etc/ufw/ufw.conf
  20. }
  21.  
  22. allow_port() {
  23.     ufw allow "$@" >/dev/null || true
  24. }
  25.  
  26. allow_service() {
  27.     service=`echo "$@" | sed 's/#/ /g'`
  28.     if [ "$service" = "CUPS" ]; then
  29.         allow_port 631
  30.     elif [ "$service" = "DNS" ]; then
  31.         allow_port 53
  32.     elif [ "$service" = "IMAPS" ]; then
  33.         allow_port 993/tcp
  34.     elif [ "$service" = "POP3S" ]; then
  35.         allow_port 995/tcp
  36.     elif [ "$service" = "SSH" ]; then
  37.         allow_port 22/tcp
  38.     elif [ "$service" = "CIFS (Samba)" ]; then
  39.         allow_port 137/udp
  40.         allow_port 138/udp
  41.         allow_port 139/tcp
  42.         allow_port 445/tcp
  43.     elif [ "$service" = "SMTP" ]; then
  44.         allow_port 25/tcp
  45.     elif [ "$service" = "HTTP" ]; then
  46.         allow_port 80/tcp
  47.     elif [ "$service" = "HTTPS" ]; then
  48.         allow_port 443/tcp
  49.     fi
  50. }
  51.  
  52. case "$1" in
  53.     configure)
  54.         # these files are required, but don't want to change them if
  55.         # the user modified them
  56.         for f in before.rules before6.rules after.rules after6.rules
  57.         do
  58.             ucf --debconf-ok $TEMPLATE_PATH/$f $RULES_PATH/$f
  59.             chmod 640 $RULES_PATH/$f
  60.         done
  61.  
  62.         for f in user.rules user6.rules
  63.         do
  64.             if [ ! -e "$USER_PATH/$f" ]; then
  65.                 # if no config, copy the template
  66.                 cp $TEMPLATE_PATH/$f $USER_PATH/$f
  67.                 chmod 640 $USER_PATH/$f
  68.             fi
  69.         done
  70.  
  71.         # https://bugs.launchpad.net/ufw/+bug/393187
  72.         if dpkg --compare-versions "$2" lt 0.27.1-2 ; then
  73.             for f in before.rules before6.rules after.rules after6.rules
  74.             do
  75.                 test -f $RULES_PATH/$f && chmod o-rwx $RULES_PATH/$f
  76.             done
  77.             for f in user.rules user6.rules
  78.             do
  79.                 test -f $USER_PATH/$f && chmod o-rwx $USER_PATH/$f
  80.             done
  81.         fi
  82.  
  83.         if [ ! -e "/etc/ufw/ufw.conf" ]; then
  84.             cp $TEMPLATE_PATH/ufw.conf /etc/ufw
  85.         fi
  86.  
  87.         if [ ! -z "$2" ] && dpkg --compare-versions "$2" lt "0.24.1" ; then
  88.             # remove these symlinks for existing installations
  89.             rm -f /etc/rc0.d/K39ufw
  90.             rm -f /etc/rc6.d/K39ufw
  91.         fi
  92.  
  93.         # configure ufw with debconf values
  94.         db_get ufw/enable
  95.         enabled="$RET"
  96.  
  97.         db_fget ufw/existing_configuration seen
  98.         seen_warning="$RET"
  99.         if [ "$enabled" = "true" ] && [ "$seen_warning" = "false" ] ; then
  100.             db_get ufw/allow_known_ports
  101.             CHOICES="$RET"
  102.             for service in `echo "$CHOICES" | sed 's/, /\n/g' | sed 's/ /#/g'`; do
  103.                 allow_service "$service"
  104.             done
  105.  
  106.             db_get ufw/allow_custom_ports
  107.             PORTS="$RET"
  108.             for port in $PORTS ; do
  109.                 allow_port "$port"
  110.             done
  111.  
  112.             db_fset ufw/existing_configuration seen true
  113.         fi
  114.  
  115.         # need to do this after all 'allow_service' calls, otherwise ufw may
  116.         # try to use iptables, which breaks the installer
  117.         enable_ufw "$enabled"
  118.         ;;
  119.     triggered)
  120.         ufw app update all || echo "Processing ufw triggers failed. Ignoring."
  121.         exit 0
  122.         ;;
  123.     abort-upgrade|abort-remove|abort-deconfigure)
  124.         ;;
  125.     *)
  126.         echo "postinst called with unknown argument '$1'" >&2
  127.         exit 1
  128.         ;;
  129. esac
  130.  
  131. # Automatically added by dh_installinit
  132. update-rc.d -f ufw remove >/dev/null || exit $?
  133. # End automatically added section
  134. # Automatically added by dh_pycentral
  135. rm -f /var/lib/pycentral/ufw.pkgremove
  136. if which pycentral >/dev/null 2>&1; then
  137.     pycentral pkginstall ufw
  138.     if grep -qs '^ufw$' /var/lib/pycentral/delayed-pkgs; then
  139.         sed -i '/^ufw$/d' /var/lib/pycentral/delayed-pkgs
  140.     fi
  141. fi
  142. # End automatically added section
  143.  
  144.